package com.bpmn.flow.controller;

import cn.hutool.json.JSONUtil;
import com.bpmn.api.BpmTaskCallbackReqDTO;
import com.bpmn.common.entity.ResponseResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @author rain
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "callback")
public class CallbackController {

    /**
     * 回调用户
     */
    @PostMapping("/userCallbackAddress")
    public ResponseResult<Set<String>> userCallbackAddress(@RequestBody BpmTaskCallbackReqDTO dto) {
        // 处理服务回调
        String jsonStr = JSONUtil.toJsonStr(dto);
        //用户回调处理
        log.info("回调用户回调参数：{}", jsonStr);
        return ResponseResult.success(Set.of("1912071522803097600", "1912071522803097601", "1912071522803097602",
                "1912071522803097603", "1912071522803097604"));
    }

    /**
     * 回调方法
     */
    @PostMapping("/taskCallbackAddress")
    public ResponseResult<Boolean> taskCallbackAddress(@RequestBody BpmTaskCallbackReqDTO dto) {
        // 处理服务回调
        String jsonStr = JSONUtil.toJsonStr(dto);
        //用户回调处理
        log.info("回调方法回调参数：{}", jsonStr);
        return ResponseResult.success();
    }

}
